import './assets/main.css'

import { createApp } from 'vue'
import App from './App.vue'
import router from './router'
import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'
import 'amfe-flexible'
import {config} from '@/common/config.js'
import {post,get,del,put,upload,downloadFile} from '@/common/function.js'
import zhCn from 'element-plus/dist/locale/zh-cn.mjs'
import 'element-plus/dist/index.css'
import * as ElementPlusIconsVue from '@element-plus/icons-vue'

const app = createApp(App)
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
    app.component(key, component)
}
app.use(router)
app.use(ElementPlus, {
    locale: zhCn,
})
app.mount('#app')
app.config.globalProperties.getType = function(type = ""){
    let returnType = 0
    switch (type){
        case 'image/jpeg':
        case 'image/png':
        case 'image/gif':
            returnType = 1
            break;
        case 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet':
        case 'application/vnd.openxmlformats-officedocument.wordprocessingml.document':
        case 'application/pdf':
        case 'application/msword':
        case 'application/vnd.ms-excel':
            returnType = 2
            break;
    }
    return returnType;
}
app.config.globalProperties.$upload = upload
app.config.globalProperties.$downloadFile = downloadFile
app.config.globalProperties.getImagePath = function(path = "",type = "api_url"){
    if(path != ""){
        if(path.indexOf('http://') < 0 && path.indexOf('https://') < 0){
            return config[type]+path
        }
        return path
    }
    return path
}
app.config.globalProperties.getIframeSrc = function (route = ""){
    if(route != ''){
        if(route.indexOf('http://') < 0 && route.indexOf('https://') < 0){
            return config.local_domain_name+route
        }
        return route
    }
    return route
}
app.config.globalProperties.$post = post
app.config.globalProperties.$get = get
app.config.globalProperties.$put = put
app.config.globalProperties.$del = del
app.config.globalProperties.toPath = async function(path = ""){
    this.$router.push(path)

}
app.config.globalProperties.getParams = function GetQueryString(name = "") {
    var reg = new RegExp('(^|&)' + name + '=([^&]*)(&|$)', 'i');
    var r = window.location.search.substr(1).match(reg);
    if (r != null) {
        return unescape(r[2]);
    }
    return null;
}
